package net.maxwoods.springcloud;/**
 * @description:
 * @authoer: Max Woods
 * @create:2018/7/9 11:35
 **/

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.gateway.route.Route;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.PredicateSpec;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;

import java.util.function.Function;

/**
 *@auther: Max Woods
 *@create:2018/7/9 11:35
 **/
@SpringBootConfiguration
@EnableAutoConfiguration
public class Gateway {

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        /*
        Function<PredicateSpec, Route.AsyncBuilder> fn = new Function<PredicateSpec, Route.AsyncBuilder>() {

            public Route.AsyncBuilder apply(PredicateSpec t) {
                t.path("/hello");
                return t.uri("http://localhost:8080");
            }
        };
        */
        Function<PredicateSpec, Route.AsyncBuilder> a1=(PredicateSpec t)->
            t.path("/hello").and().uri("http://localhost:20000");
        Function<PredicateSpec, Route.AsyncBuilder> a2=(PredicateSpec t)->
                t.path("/woods").and().uri("http://www.maxwoods.net");
        return builder.routes().route(a1).route(a2).build();
    }

    public static void main(String[] args) {
        SpringApplication.run(Gateway.class, args);
    }
}
